package com.sunfeng.n3;


import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * 打断睡眠的线程 会抛出异常打断标记被置为false
 *
 * @author sunfeng
 */
@Slf4j(topic = "c.Test11")
public class Test11 {
    public static void main(String[] args) throws InterruptedException {


        Thread t1 = new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(5);  //wait  join 被打断后  打断标记被置为false
            } catch (InterruptedException e) {

                e.printStackTrace();
            }
        }, "t1");
        t1.start();

        log.debug("interrupt");
        System.out.println(t1.isInterrupted());
        TimeUnit.SECONDS.sleep(1);
        t1.interrupt();

        // 打断标记被重置
        log.debug("打断标记,{}", t1.isInterrupted());
    }
}
